<!--
 * @Author: [kangjie]
 * @Date: 2022-03-30 10:20:45
 * @LastEditors: [kangjie]
 * @LastEditTime: 2022-03-30 14:24:38
 * @Description: !
-->
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>事件修饰符</title>
  <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
  <style>
    .outer{
      width: 400px;
      height: 100px;
      background-color: red;
      overflow: scroll;
    }
    .inner{
      width: 200px;
      height: 400px;
      background-color: blue;
      margin: 0 auto;
    }
  </style>
</head>

<body>
  <div id="app">
    <!-- 键盘按下事件 -->
    <!-- <input type="text" @keyup.13="handlerKeyup"> -->
    <!-- 鼠标按下事件 -->
    <input type="text" @mouseup.left="handlerKeyup">
    <!-- pervent 阻止事件的默认行为 -->
    <!-- once 事件执行一次后解绑 事件修饰符可以连用 -->
    <a href="https://www.baidu.com" @click.prevent.once="toJump">百度一下</a>
    <!-- 让事件再捕获阶段执行 capture 从外向内-->
    <!-- <div class="outer" @click.capture="outer">outer -->
      <!-- 只有当前事件对象为event.target时候执行事件 -->
      <!-- <div class="outer" @click.self="outer">outer -->
        <!-- 滚动行为 立即触发 passive 一般与scroll -->
        <div class="outer" @scroll.passive="outer">outer
      <!-- 阻止事件冒泡的事件修饰符 stop-->
      <!-- <div class="inner" @click.stop="inner">inner</div> -->
      <div class="inner" @click="inner">inner</div>
    </div>
  </div>
  <script>
    new Vue({
      el: '#app',
      data: {

      }, methods: {
        handlerKeyup(event){
          console.log('按下某些特殊键');
        },
        // 跳转
        toJump(event){
          console.log('跳转');
          // 阻止事件的默认行为
          // event.preventDefault();
        },
        inner(event){
          console.log('inner');
          console.log(event.target,'触发事件的源目标');
          console.log(event.currentTarget,'当前事件执行的目标')
          // 阻止事件冒泡
          // event.stopPropagation()
        },
        outer(event){
          console.log('outer');
          for(let i=0;i<101;i++){
            console.log(i);
          }
          // console.log(event.target,'触发事件的源目标');
          // console.log(event.currentTarget,'当前事件执行的目标')
        }
      }
    })
  </script>

</body>

</html>